#include "player.h"
#include <string.h>
#include <stdio.h>

#include "../../equipment/equiptest.h"

Player::Player(char* n):ObjCommon(n)
{
	head = body = arm = leg = finger = weapon = Equipment();
	initVals();
	initMyEquips();
}

void Player::initMyEquips()
{
	Equipment* eq[] = {&head,&body,&arm,&leg,&finger,&weapon};
	memcpy(myEquips,eq,sizeof(myEquips));
}

void Player::initVals()
{
	health = HealthVals(100,50);
	fight = FightVals(10,5);
	defence = DefenceVals(1,1);
}

Equipment Player::wear(Equipment& e)
{
	if(e.where == Equipment::NONE)
	{
		return Equipment();
	}

	Equipment r;
	r = *(myEquips[e.where]);
	*(myEquips[e.where]) = e;

	update();
	return r;
}

void Player::update()
{
	initVals();

	//level and vals
	float grow = (float)(level -1);
	HealthVals		hg(1,1);
	FightVals		fg(1,1);
	DefenceVals		dg(1,1);
	hg*= grow; fg*= grow; dg*= grow;
	hg.mul(10.0f,8.0f); fg.mul(2.3f,1.5f); dg.mul(1.3f,1.0f);
	health += hg;
	fight += fg;
	defence += dg;

	//equipments
	for(int i = 0 ; i < EQUIP_NUM; i++)
	{
		health += myEquips[i]->health;
		fight += myEquips[i]->fight;
		defence += myEquips[i]->defence;
	}
}

void Player::showEquipsInfo()
{
	
	for(int i = 0 ; i < EQUIP_NUM; i++)
	{
		showEquipInfo(*myEquips[i]);
	}
}
